package com.siyuanren.gcocp.service.impl;

import com.siyuanren.gcocp.base.BaseObject;
import com.siyuanren.gcocp.entity.WxCourseContent;
import com.siyuanren.gcocp.entity.WxUserFavorite;
import com.siyuanren.gcocp.mapper.MyWxContentMapper;
import com.siyuanren.gcocp.mapper.base.WxUserFavoriteMapper;
import com.siyuanren.gcocp.service.FavoriteService;
import com.siyuanren.gcocp.vo.QueryFavoritesVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by   anxing
 * Project_name gcocp-parent
 * Path         com.siyuanren.gcocp.service.impl
 * Date         2018/4/17
 * Time         15:20
 * Description
 */
@Slf4j
@Service
public class FavoriteServiceImpl extends BaseObject implements FavoriteService {
    @Autowired
    WxUserFavoriteMapper favoriteMapper;
    @Autowired
    MyWxContentMapper myWxContentMapper;

    @Override
    @Transactional
    public int addFavoriteContent(WxUserFavorite userFavorite) {
        int index = favoriteMapper.insertSelective(userFavorite);
        return index;
    }

    @Override
    @Transactional
    public void removeFavoriteContent(int favoriteId) {
        favoriteMapper.deleteByPrimaryKey(favoriteId);
    }

    @Override
    public List<WxCourseContent> getFavorierList(QueryFavoritesVO queryFavoritesVO) throws Exception {
        log.info(queryFavoritesVO.toString());
        return myWxContentMapper.getFavoriteContentList(queryFavoritesVO);
    }
}
